<?php
class UserLogin {

	private $daten;
	private $loggin_error;
	private $System;

	public function __construct($match) {
		$this->daten = $match;
	}

	public function getWort(RainTPL $design) {
		$this->design = $design;
	    $login = "";
		if ($this->design->post->gfw_email && $this->design->post->gfw_password) {
		    $loginObj = new Db_User();
			$login = $loginObj->LoginCheck ( $this->design->post->gfw_email, $this->design->post->gfw_password);

			if ($login) {
				$loginObj->Login();
				$LoginData = new Db_User();
				$LoginData = $LoginData->GetUserByEmail($this->design->post->gfw_email);
				
				$_SESSION ['UserId'] = $LoginData->id;
				$_SESSION ['UserName'] = $LoginData->username;
				
				HTTP::redirect ( ConfigFile::Get('BASE_DIR') . '/' );
			} else {
				$this->loggin_error = LOGIN_ERROR;
			}
		} elseif ($this->design->get->out) {
			unset ( $_SESSION ['UserId'] );
			unset ( $_SESSION ['UserWho'] );
				
			HTTP::redirect ( ConfigFile::Get('BASE_DIR') . '/' );
		}

		if ($this->loggin_error) {
			$this->design->assign ( 'Error', $this->loggin_error );
		}
		        
		$this->design->assign ('css',"loginscreen");
		$this->design->assign ('js',"jsLoginScreen");
		
	    if( $cache = $this->design->cache( $this->design->ln.'/login/login', $expire_time = 600) )
	    {						       
	        echo $cache;
	    }
	    else
	    { 
	        $this->design->draw( $this->design->ln.'/login/login' );						        
	    }		       
	}

}
?>